#include "proxydlg.h"
#include "ui_proxydlg.h"

#include <QNetworkProxy>

ProxyDlg::ProxyDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ProxyDlg)
{
    ui->setupUi(this);
    connect(this, SIGNAL(accepted()), this, SLOT(setProxy()));
    connect(this, SIGNAL(rejected()), this, SLOT(unsetProxy()));
}

ProxyDlg::~ProxyDlg()
{
    delete ui;
}

void ProxyDlg::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void ProxyDlg::setProxy()
{
    QNetworkProxy proxy;
    proxy.setType(QNetworkProxy::HttpProxy);
    proxy.setHostName(ui->txtHttpServer->text());
    proxy.setPort(ui->txtHttpPort->text().toInt());
    QNetworkProxy::setApplicationProxy(proxy);
}

void ProxyDlg::unsetProxy()
{
    QNetworkProxy::applicationProxy().setType(QNetworkProxy::NoProxy);
}

